use std::{
    hash::{DefaultHasher, Hash, Hasher},
    hint::black_box,
};

use criterion::Criterion;

use cs2s::sign::CodeSign;
use rustc_hash::FxHasher;

pub fn calculation(c: &mut Criterion) {
    macro_rules! bench {
        ($($i:literal),*) => {
            $(
                c.bench_function(concat!("calculate ", stringify!($i), " B code"), |b| {
                    b.iter(|| {
                        let sign: CodeSign = [0x5Fu8; $i].into();
                        black_box(sign)
                    })
                });
            )*
        };
    }

    bench!(1, 32, 64, 1024, 4096);
}

pub fn hasher(c: &mut Criterion) {
    let addr: usize = 0x400000;
    let size: usize = 1024;
    let sign: CodeSign = [].into();

    let mut group = c.benchmark_group("compare hasher");
    group.bench_function("default", |b| {
        b.iter(|| {
            let mut df_hasher = DefaultHasher::default();
            addr.hash(&mut df_hasher);
            size.hash(&mut df_hasher);
            sign.hash(&mut df_hasher);
            black_box(df_hasher.finish());
        })
    });
    group.bench_function("fx", |b| {
        b.iter(|| {
            let mut fx_hasher = FxHasher::default();
            addr.hash(&mut fx_hasher);
            size.hash(&mut fx_hasher);
            sign.hash(&mut fx_hasher);
            black_box(fx_hasher.finish());
        })
    });
    group.finish();
}
